import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from os.path import join,dirname
import otsu_pro
import otsu_pro_float
import math


name="2024-03-23-20-07-09-208404.png"

DIR = dirname(__file__)

path=join(DIR, "gray_scale_188_120", name)

img=mpimg.imread(path)
copy_img=img

'''
for i in range (0,188):
    for j in range (0,120):
        copy_img[j][i]=img[j][i]*255
        copy_img[j][i]=math.floor(copy_img[j][i])
        if copy_img[j][i]>255:
            copy_img[j][i]=255
        copy_img[j][i]=int(copy_img[j][i])
        # if copy_img[j][i]>255:
        #     copy_img[j][i]=255

# print(copy_img)

'''

threshold=otsu_pro_float.otsu_threshold_float(copy_img)
#threshold=otsu_pro.otsu_threshold(copy_img)

#print(threshold)

# threshold=threshold/255.0

print(img)
print(threshold)

# j行i列
for i in range (0,188):
    for j in range (0,120):
        # img[j][i]=120
        if img[j][i]>threshold:
            img[j][i]=1
        else:
            img[j][i]=0


plt.imshow(img,cmap='gray')
plt.show()
